﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class User_send : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (IsValid == true)
        {
            SqlConnection strcon = Class1.DBconnection();
            strcon.Open();
            string Username = this.Username.Text.ToString();
            string Userpwd = this.Userpwd.Text.ToString();
            string CompanyName = this.CompanyName.Text.ToString();
            string UserType = this.UserType.Text.ToString();
            string Linkman = this.Linkman.Text.ToString();
            string Tel = this.Tel.Text.ToString();
            string MobileTelephone = this.MobileTelephone.Text.ToString();
            //string Email = this.Email.Text.ToString();
            string Address = this.Address.Text.ToString();
            string Postalcode = this.Postalcode.Text.ToString();
            string Bewrite = this.Bewrite.Text.ToString();
            string Problem = this.Problem.Text.ToString();
            string Answer = this.Answer.Text.ToString();
            string AddNow = Convert.ToString(DateTime.Now);
            SqlCommand scd1 = new SqlCommand("insert into tb_User (Username,Userpwd,CompanyName,UserType,Linkman,Tel,MobileTelephone,Address,Postalcode,Bewrite,AddNow,Problem,Answer)values('" + Username + "','" + Userpwd + "','" + CompanyName + "','" + UserType + "','" + Linkman + "','" + Tel + "','" + MobileTelephone +  "','" + Address + "','" + Postalcode + "','" + Bewrite + "','" + AddNow + "','" + Problem + "','" + Answer + "')", strcon);
            scd1.ExecuteNonQuery();
            Response.Write("<script lanuage=javascript>alert('注册成功，请等待审核。');location='User_send.aspx'</script>");
        }
    }
    protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        SqlConnection strcon = Class1.DBconnection();
        strcon.Open();
        string username = this.Username.Text.ToString();
        SqlCommand cmd = new SqlCommand("select count(*) from tb_User where username='" + username + "'", strcon);
        int count = Convert.ToInt32(cmd.ExecuteScalar());
        if (count > 0)
        {
            args.IsValid=false;
        }
        else
        {
            args.IsValid = true;
        }
    }
}
